#pragma once
#include "p2.h"
#include "AccountInfo.h"
#include "GxAccountEventSink.h"
#include "PositionInfo.h"
#include "AccountEventSink.h"
#include "PositionEventSink.h"

class CMainOrderPanel;

class CAccountManager
{
public:
	CAccountManager(IGxServer& a_Server);
	
	CAccountManager();
	~CAccountManager();

	
	IGxServer m_Server;
	void OnAccountUndated();
	CAccountInfo* RefreshAccount();

	CMainOrderPanel* MainWnd() const { return m_pMainWnd; }
	void MainWnd(CMainOrderPanel* val) { m_pMainWnd = val; }

	CAccountEventSink m_AccountSink;
	CString m_AccountCode;

	void ChangeAccount(CString a_AccountCode);
	void AdviseEvent();
	void UnadviseEvent();
	void AddAccounts();

	mapPosition m_PositionMap;

	CPositionInfo* AddPosition(wstring a_Key);
	CPositionInfo* FindPosition(wstring a_Key);


	void AdvisePositionEvent();
	void UnadvisePositionEvent();

	void OnNewPosition(IGxPosition a_GxPosition);
	void OnPositionUpdated(IGxPosition a_GxPosition);
	void OnEvalPLUpdated(IGxPosition a_GxPosition);

	void RefreshPositions();
	CPositionEventSink m_PositionSink;
private:

	CMainOrderPanel* m_pMainWnd;
};

